package com.rocsea.robot.template.impl;

import com.rocsea.robot.config.build.TemplateInfo;
import com.rocsea.robot.factory.KettleTemplateFactory;
import com.rocsea.robot.model.entity.StepAttributeDO;
import com.rocsea.robot.model.enums.KettleBuildStrategyEnum;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;

/**
 * first_batch移除update_time_id
 * @Author RocSea
 * @Date 2022/12/7
 *
 */
@Component
public class FirstBatchRemoveUpdateTimeIdTemplate extends FirstBatchTemplate {

    @Override
    public TemplateInfo getTemplateInfo() {
        return getTemplateConfig().getFirstBatchRemoveUpdateTimeId();
    }

    @Override
    public String processTableInput(List<StepAttributeDO> stepAttributeDOS) throws IOException {
        return super.processTableInputWithRowMeta(stepAttributeDOS);
    }

    @Override
    public String processSqlReplace(String sql) {
        return sql.substring(sql.indexOf("FROM"));
    }

    @Override
    public String processQueryFromTableName(List<StepAttributeDO> stepAttributeDOS) throws IOException {
        return super.processTableInputWithRowMeta(stepAttributeDOS);
    }

    @Override
    public String processKettleTaskConfig() throws ParseException {
        return getKettleTaskConfigService().buildKettleTaskConfig(true);
    }

    @Override
    public void afterPropertiesSet() {
        KettleTemplateFactory.register(KettleBuildStrategyEnum.FIRST_BATCH_REMOVE_UPDATE_TIME_ID.getText(), this);
    }

}
